import React from 'react';
import { BrowserRouter as Router, Routes, Route, Navigate } from 'react-router-dom';
import { ConfigProvider } from 'antd';
import zhCN from 'antd/locale/zh_CN';
import { AuthProvider } from './context/AuthContext';
import { MessageProvider } from './context/MessageContext';
import MainLayout from './layouts/MainLayout';
import Login from './pages/Login';
import Register from './pages/Register';
import ForgotPassword from './pages/ForgotPassword';
import ResetPassword from './pages/ResetPassword';
import EmailVerification from './pages/EmailVerification';
import Home from './pages/Home';

// 种子相关页面
import TorrentList from './pages/torrent/TorrentList';
import TorrentDetail from './pages/torrent/TorrentDetail';
import TorrentUpload from './pages/torrent/TorrentUpload';

// 论坛相关页面
import ForumSections from './pages/forum/ForumSections';
import ForumTopics from './pages/forum/ForumTopics';
import ForumTopicDetail from './pages/forum/ForumTopicDetail';
import ForumTopicCreate from './pages/forum/ForumTopicCreate';

// 私信相关页面
import MessageInbox from './pages/message/MessageInbox';
import MessageDetail from './pages/message/MessageDetail';
import ComposeMessage from './pages/message/ComposeMessage';

// 管理员相关页面
import UserManagement from './pages/admin/UserManagement';
import TorrentManagement from './pages/admin/TorrentManagement';
import AdminStats from './pages/admin/AdminStats';
import InvitationManagement from './pages/admin/InvitationManagement';
import PasswordTest from './pages/admin/PasswordTest';

// 求种相关页面
import RequestList from './pages/request/RequestList';
import RequestCreate from './pages/request/RequestCreate';
import RequestDetail from './pages/request/RequestDetail';

// 其他页面
import TrackerStatus from './pages/TrackerStatus';
import Profile from './pages/Profile';
import Settings from './pages/Settings';
import UserProfile from './pages/UserProfile';

import './App.css';

function App() {
  return (
    <ConfigProvider locale={zhCN}>
      <AuthProvider>
        <MessageProvider>
          <Router>
            <Routes>
              {/* 独立的认证页面路由 */}
              <Route path="/login" element={<Login />} />
              <Route path="/register" element={<Register />} />
              <Route path="/forgot-password" element={<ForgotPassword />} />
              <Route path="/reset-password" element={<ResetPassword />} />
              <Route path="/verify-email" element={<EmailVerification />} />
              
              {/* 需要认证的主要页面 */}
              <Route path="/" element={<MainLayout />}>
                <Route index element={<Home />} />
                <Route path="torrents" element={<TorrentList />} />
                <Route path="torrents/:id" element={<TorrentDetail />} />
                <Route path="upload" element={<TorrentUpload />} />
                <Route path="requests" element={<RequestList />} />
                <Route path="requests/new" element={<RequestCreate />} />
                <Route path="requests/:id" element={<RequestDetail />} />
                <Route path="forum" element={<ForumSections />} />
                <Route path="forum/sections/:sectionId" element={<ForumTopics />} />
                <Route path="forum/topics/:topicId" element={<ForumTopicDetail />} />
                <Route path="forum/new-topic" element={<ForumTopicCreate />} />
                <Route path="messages" element={<MessageInbox />} />
                <Route path="messages/:id" element={<MessageDetail />} />
                <Route path="messages/compose" element={<ComposeMessage />} />
                <Route path="admin/users" element={<UserManagement />} />
                <Route path="admin/torrents" element={<TorrentManagement />} />
                <Route path="admin/stats" element={<AdminStats />} />
                <Route path="admin/invitations" element={<InvitationManagement />} />
                <Route path="admin/password-test" element={<PasswordTest />} />
                <Route path="admin" element={<Navigate to="/admin/users" replace />} />
                <Route path="tracker-status" element={<TrackerStatus />} />
                <Route path="profile" element={<Profile />} />
                <Route path="user/:userId" element={<UserProfile />} />
                <Route path="settings" element={<Settings />} />
              </Route>
              
              <Route path="*" element={<Navigate to="/" replace />} />
            </Routes>
          </Router>
        </MessageProvider>
      </AuthProvider>
    </ConfigProvider>
  );
}

export default App;
